import React, { Component } from "react";
import PropTypes from "prop-types"; //类型限制
import "./index.css";
export default class Footer extends Component {

  static propTypes = {
    checkAllTodo: PropTypes.func.isRequired,
    clearAllDone: PropTypes.func.isRequired
  }

  // 是否全选
  checkAllStatus = (event) => {
    this.props.checkAllTodo(event.target.checked)
  }

  //清除所有已完成的列表
  headleClearAllDone = () => {
    this.props.clearAllDone()
  }

  render() {
    const { todos } = this.props
    const fulfill = todos.filter(item => item.done).length
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" onChange={this.checkAllStatus} checked={(fulfill === todos.length && todos.length !== 0 ? true : false)} />
        </label>
        <span>
          <span>已完成{fulfill}</span> / 全部{todos.length}
        </span>
        <button className="btn btn-danger" onClick={this.headleClearAllDone}>清除已完成任务</button>
      </div>
    );
  }
}
